package com.mvd.app.activitys;

import android.text.TextUtils;

import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.CarsInforModel;

/**
 * Created by leilei on 2025/9/9 0009.
 */

public class HeightChecker {
    // 车辆Code与Name对应二维数组：每个子数组格式为 [Code, Name]
    public   final String[][] VEHICLE_CODE_NAME_ARRAY = {
            {"H11", "重型栏板货车"},
            {"H12", "重型厢式货车"},
            {"H13", "重型封闭式货车"},
            {"H14", "重型罐式货车"},
            {"H15", "重型平板货车"},
            {"H16", "重型集装箱车"},
            {"H17", "重型自卸货车"},
            {"H18", "重型特殊结构货车"},
            {"H19", "重型仓栅式货车"},
            {"H1A", "重型车辆运输车"},
            {"H1B", "重型厢式自卸货车"},
            {"H1C", "重型罐式自卸货车"},
            {"H1D", "重型平板自卸货车"},
            {"H1E", "重型集装箱自卸货车"},
            {"H1F", "重型特殊结构自卸货车"},
            {"H1G", "重型仓栅式自卸货车"},
            {"H1J", "重型专门用途货车"},
            {"H21", "中型栏板货车"},
            {"H22", "中型厢式货车"},
            {"H23", "中型封闭式货车"},
            {"H24", "中型罐式货车"},
            {"H25", "中型平板货车"},
            {"H26", "中型集装箱车"},
            {"H27", "中型自卸货车"},
            {"H28", "中型特殊结构货车"},
            {"H29", "中型仓栅式货车"},
            {"H2A", "中型车辆运输车"},
            {"H2B", "中型厢式自卸货车"},
            {"H2C", "中型罐式自卸货车"},
            {"H2D", "中型平板自卸货车"},
            {"H2E", "中型集装箱自卸货车"},
            {"H2F", "中型特殊结构自卸货车"},
            {"H2G", "中型仓栅式自卸货车"},
            {"H2J", "中型专门用途货车"},
            {"H31", "轻型栏板货车"},
            {"H32", "轻型厢式货车"},
            {"H33", "轻型封闭式货车"},
            {"H34", "轻型罐式货车"},
            {"H35", "轻型平板货车"},
            {"H37", "轻型自卸货车"},
            {"H38", "轻型特殊结构货车"},
            {"H39", "轻型仓栅式货车"},
            {"H3A", "轻型车辆运输车"},
            {"H3B", "轻型厢式自卸货车"},
            {"H3C", "轻型罐式自卸货车"},
            {"H3D", "轻型平板自卸货车"},
            {"H3E", "轻型集装箱自卸货车"},
            {"H3F", "轻型特殊结构自卸货车"},
            {"H3G", "轻型仓栅式自卸货车"},
            {"H3H", "轻型多用途货车"},
            {"H3J", "轻型专门用途货车"},
            {"H41", "微型栏板货车"},
            {"H42", "微型厢式货车"},
            {"H43", "微型封闭式货车"},
            {"H44", "微型罐式货车"},
            {"H45", "微型自卸货车"},
            {"H46", "微型特殊结构货车"},
            {"H47", "微型仓栅式货车"},
            {"H4A", "微型车辆运输车"},
            {"H4B", "微型厢式自卸货车"},
            {"H4C", "微型罐式自卸货车"},
            {"H4F", "微型特殊结构自卸货车"},
            {"H4G", "微型仓栅式自卸货车"},
            {"H4H", "微型多用途货车"},
            {"H4J", "微型专门用途货车"},
            {"H51", "栏板低速货车"},
            {"H52", "厢式低速货车"},
            {"H53", "罐式低速货车"},
            {"H54", "自卸低速货车"},
            {"H55", "仓栅式低速货车"},
            {"H5B", "厢式自卸低速货车"},
            {"H5C", "罐式自卸低速货车"}
    };

    public   final String[][] ZI_XIE_CHE = {
            {"H1B", "重型厢式自卸货车"},
            {"H1C", "重型罐式自卸货车"},
            {"H1D", "重型平板自卸货车"},
            {"H1E", "重型集装箱自卸货车"},
            {"H1F", "重型特殊结构自卸货车"},
            {"H1G", "重型仓栅式自卸货车"},
            {"H2B", "中型厢式自卸货车"},
            {"H2C", "中型罐式自卸货车"},
            {"H2D", "中型平板自卸货车"},
            {"H2E", "中型集装箱自卸货车"},
            {"H2F", "中型特殊结构自卸货车"},
            {"H2G", "中型仓栅式自卸货车"},
            {"H3B", "轻型厢式自卸货车"},
            {"H3C", "轻型罐式自卸货车"},
            {"H3D", "轻型平板自卸货车"},
            {"H3E", "轻型集装箱自卸货车"},
            {"H3F", "轻型特殊结构自卸货车"},
            {"H3G", "轻型仓栅式自卸货车"},
            {"H4B", "微型厢式自卸货车"},
            {"H4C", "微型罐式自卸货车"},
            {"H4F", "微型特殊结构自卸货车"},
            {"H4G", "微型仓栅式自卸货车"},
            {"H5B", "厢式自卸低速货车"},
            {"H5C", "罐式自卸低速货车"}
    };
    // 仅包含车辆Code的一维数组，按原始顺序排列
    public   final String[] VEHICLE_CODE_ARRAY = {
            "H11", "H12", "H13", "H14", "H15", "H16", "H17", "H18", "H19", "H1A",
            "H1B", "H1C", "H1D", "H1E", "H1F", "H1G", "H1J", "H21", "H22", "H23",
            "H24", "H25", "H26", "H27", "H28", "H29", "H2A", "H2B", "H2C", "H2D",
            "H2E", "H2F", "H2G", "H2J", "H31", "H32", "H33", "H34", "H35", "H37",
            "H38", "H39", "H3A", "H3B", "H3C", "H3D", "H3E", "H3F", "H3G", "H3H",
            "H3J", "H41", "H42", "H43", "H44", "H45", "H46", "H47", "H4A", "H4B",
            "H4C", "H4F", "H4G", "H4H", "H4J", "H51", "H52", "H53", "H54", "H55",
            "H5B", "H5C"
    };
    // 仅包含自卸车Code的一维数组，按原始顺序排列
    public   final String[] ZI_XIE_CHE_CODE = {
            "H1B", "H1C", "H1D", "H1E", "H1F", "H1G",
            "H2B", "H2C", "H2D", "H2E", "H2F", "H2G",
            "H3B", "H3C", "H3D", "H3E", "H3F", "H3G",
            "H4B", "H4C", "H4F", "H4G",
            "H5B", "H5C"
    };
    public static CarsInforModel carsInforModel;

    public HeightChecker(CarsInforModel carsInforModel) {
        this.carsInforModel = carsInforModel;
    }

    public   boolean is_Gua() {
        return carsInforModel.getPlateType().contains("15") ? true : false;
    }

    public   boolean is_Zi_Xie() {
        boolean result = false;
        for (int i = 0; i < ZI_XIE_CHE_CODE.length; i++) {
            if (carsInforModel.getType().equals(ZI_XIE_CHE_CODE[i])) {
                result = true;
                break;
            }
        }
        return result;
    }

    public   boolean get_hight_result(String chexiang_lanban_gaodu, String gua_che_lanban_gaodu) {
        String logStr = "\n" + "车辆特征参数--栏板高度判断---" + "\n" +
                "chexiang_lanban_gaodu::" +  chexiang_lanban_gaodu+ "\n"+
                "gua_che_lanban_gaodu::" + gua_che_lanban_gaodu + "\n"+
                "type::" + carsInforModel.getType() + "\n";

        boolean result = false;
        int maxAllowedHeight = 0;
        // String chexiang_lanban_gaodu = acWaijianItemChexiangLanbanGaodu.getText().toString().trim();
        // String gua_che_lanban_gaodu = acWaijianItemGuaChexiangLanbanGaodu.getText().toString().trim();
        int totalAxis = Integer.parseInt(carsInforModel.getTotalAxis());//总轴数
        if (carsInforModel.getPlateType().contains("15")) {
            //挂车
            logStr+= "挂车=600==totalAxis::" + totalAxis + "\n";
            maxAllowedHeight = 600;
            if (!TextUtils.isEmpty(gua_che_lanban_gaodu)&&TextUtils.isDigitsOnly(chexiang_lanban_gaodu)) {
                int gua_lanban = Integer.valueOf(gua_che_lanban_gaodu);
                if(gua_lanban<=maxAllowedHeight){
                    int absDiff = Math.abs(maxAllowedHeight - gua_lanban);
                    result = absDiff <= 50 ? true : false;
                }
            }
        } else {
            int lanban = 0;
            if (!TextUtils.isEmpty(chexiang_lanban_gaodu)&&TextUtils.isDigitsOnly(chexiang_lanban_gaodu)) {
                lanban = Integer.valueOf(chexiang_lanban_gaodu);
            }
            if (totalAxis == 2) {
                //二轴货车，二轴自卸车
                if (is_Zi_Xie()) {
                    logStr+= "二轴自卸车=800==totalAxis::" + totalAxis + "\n";
                    //二轴自卸车
                    maxAllowedHeight = 800;
                    if(lanban<=maxAllowedHeight){
                        int absDiff = Math.abs(maxAllowedHeight - lanban);
                        result = absDiff <= 50 ? true : false;
                    }
                } else {
                    logStr+= "二轴货车=600==totalAxis::" + totalAxis + "\n";
                    maxAllowedHeight = 600;
                    //二轴货车
                    if(lanban<=maxAllowedHeight){
                        int absDiff = Math.abs(maxAllowedHeight - lanban);
                        result = absDiff <= 50 ? true : false;
                    }
                }
            } else if (totalAxis >= 3) {
                //三轴及三轴以上货车，三轴及三轴以上自卸车
                if (is_Zi_Xie()) {
                    logStr+= "三轴及三轴以上自卸车=1500==totalAxis::" + totalAxis + "\n";
                    //三轴及三轴以上自卸车
                    maxAllowedHeight = 1500;
                    if(lanban<=maxAllowedHeight){
                        int absDiff = Math.abs(maxAllowedHeight - lanban);
                        result = absDiff <= 50 ? true : false;
                    }
                } else {
                    logStr+= "三轴及三轴以上货车=800==totalAxis::" + totalAxis + "\n";
                    //三轴及三轴以上货车
                    maxAllowedHeight = 800;
                    if(lanban<=maxAllowedHeight){
                        int absDiff = Math.abs(maxAllowedHeight - lanban);
                        result = absDiff <= 50 ? true : false;
                    }
                }
            }
        }
        logStr+= "result::" + result + "\n";
        UtilsLog.e("===HeightChecker=="+logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        return result;
    }
}
